///*
// *    Copyright (c) 2018-2025, lengleng All rights reserved.
// *
// * Redistribution and use in source and binary forms, with or without
// * modification, are permitted provided that the following conditions are met:
// *
// * Redistributions of source code must retain the above copyright notice,
// * this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// * notice, this list of conditions and the following disclaimer in the
// * documentation and/or other materials provided with the distribution.
// * Neither the name of the pig4cloud.com developer nor the names of its
// * contributors may be used to endorse or promote products derived from
// * this software without specific prior written permission.
// * Author: lengleng (wangiegie@gmail.com)
// */
//
//package com.yjh.auth.wechat;
//
//
//import com.yjh.auth.service.SysUserDetailsService;
//import lombok.Getter;
//import lombok.Setter;
//import lombok.SneakyThrows;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.context.support.MessageSourceAccessor;
//import org.springframework.security.authentication.AuthenticationProvider;
//import org.springframework.security.authentication.BadCredentialsException;
//import org.springframework.security.core.Authentication;
//import org.springframework.security.core.GrantedAuthority;
//import org.springframework.security.core.SpringSecurityMessageSource;
//import org.springframework.security.core.userdetails.UserDetails;
//
//import java.util.Collection;
//
///**
// * @author lengleng
// * @date 2018/8/5
// * 手机登录校验逻辑
// * 验证码登录、社交登录
// */
//@Slf4j
//public class WechatAuthenticationProvider implements AuthenticationProvider {
//	private MessageSourceAccessor messages = SpringSecurityMessageSource.getAccessor();
////	private UserDetailsChecker detailsChecker = new PigxPreAuthenticationChecks();
//
//	@Getter
//	@Setter
//	private SysUserDetailsService userDetailsService;
//
//	@Override
//	@SneakyThrows
//	public Authentication authenticate(Authentication authentication) {
//		WechatAuthenticationToken wechatAuthenticationToken = (WechatAuthenticationToken) authentication;
//
//		String principal = wechatAuthenticationToken.getPrincipal().toString();
//
//		UserDetails userDetail = userDetailsService.loadUserByWechat(principal);
//
//		if (userDetail == null) {
//			log.debug("Authentication failed: no credentials provided");
//			throw new BadCredentialsException(messages.getMessage(
//					"AbstractUserDetailsAuthenticationProvider.noopBindAccount",
//					"Noop Bind Account(psw)"));
//		}
//
//		// 检查账号状态
//		detailsChecker.check(userDetail);
//
//		String sessionId = wechatAuthenticationToken.getSessionId();
//		Collection<? extends GrantedAuthority> auths = userDetail.getAuthorities();
//		((PigxUser)userDetail).setWechatSessionId(sessionId);
//		PigxUser pigxUser = (PigxUser)userDetail;
//		pigxUser.setWechatSessionId(sessionId);
//		WechatAuthenticationToken authenticationToken = new WechatAuthenticationToken(pigxUser,sessionId, auths);
//		authenticationToken.setDetails(wechatAuthenticationToken.getDetails());
//		return authenticationToken;
//	}
//
//	@Override
//	public boolean supports(Class<?> authentication) {
//		return WechatAuthenticationToken.class.isAssignableFrom(authentication);
//	}
//}
